package VideoStore;

public class VideoStore {
    private Video[] video = new Video[50];
    private int count;

    public void addVideo(Video video) {
        for (int i = 0; i < 50; i++) {
            if (this.video[i] == null) {
                this.video[i] = video;
                return;
            }
        }
    }

    public void checkOut(Video video) {
        for (int i = 0; i < 50; i++) {
            if (this.video[i].name.equals(video.name)) {
                if (video.hired){
                    System.out.println(video.name + "已经借出！");
                }
                else {
                    video.hired = true;
                }
                break;
            }
        }
    }

    public void returnVideo(Video video) {
        for (int i = 0; i < 50; i++) {
            if (this.video[i] == video && video.hired) {
                video.hired = false;
                break;
            }
        }
    }

    public void receiveRating(Video video, double score) {
        for (int i = 0; i < 50; i++) {
            if (this.video[i] == video) {
                video.score += score;
                video.count += 1;
                video.averageScore = video.score / video.count;
            }
        }
    }

    public void listInventory() {
        for (int i = 0; i < 50; i++) {
            if (this.video[i] != null && !this.video[i].hired) {
                System.out.println(this.video[i].name);
            }
        }
    }

    public void listAll() {
        for (int i = 0; i < 50; i++) {
            if (this.video[i] != null) {
                if (this.video[i].hired)
                    System.out.println("片名：" + this.video[i].name + "  平均评分：" + this.video[i].averageScore + "  已经借出");
                else
                    System.out.println("片名：" + this.video[i].name + "  平均评分：" + this.video[i].averageScore + "  没有借出");
            }
        }
    }
}
